import curl_cffi
from flask import Flask, request, jsonify
from get_cookie import *

app = Flask(__name__)

init_url = "https://www.goindigo.in/flights?linkNav=Flight%7CBook%7CBook"


@app.route('/Akamai/6E', methods=['POST'])
def process():
    SECRET_KEY = "c22916af4cc63ba4ca355ca448ffd28f"
    # 获取请求参数
    secret_key = request.json.get('secret_key')

    # 验证 secret_key
    if secret_key != SECRET_KEY:
        return jsonify({"error": "Invalid secret_key"}), 401

    try:
        # 调用本地获取abck的函数
        akamai = Akamai(init_url)
        cookie = akamai.start()
        if not cookie:
            return jsonify({"error": "proxy is invalid"}), 500
        # 返回结果
        return jsonify(cookie)

    except curl_cffi.curl.CurlError as e:
        return jsonify({"error": "proxy is invalid"}), 500

    except Exception as e:
        return jsonify({"error": str(e)}), 500


if __name__ == '__main__':
    app.run(debug=False, host='0.0.0.0', port=5001)
